package com.zhihui.client.alarm.controller;


import com.zhihui.client.alarm.common.Msg;
import com.zhihui.client.alarm.entity.Shotcutimage;
import com.zhihui.client.alarm.service.ShotcutimageService;
import com.zhihui.client.alarm.util.FileUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.UUID;

@Controller
@RequestMapping("/tpurl")
public class UrlController {

    @Resource
    private ShotcutimageService shotcutimageService;

    @RequestMapping("/upload")
    @ResponseBody
    public Msg upload(HttpServletRequest request, MultipartFile file, Shotcutimage shotcutimage){
        Msg msg=new Msg();
        // String contentType = file.getContentType();
        String fileName = file.getOriginalFilename();//获取文件名称
        System.out.println("fileName-->" + fileName);
        // System.out.println("getContentType-->" + contentType);
        String filePath = "../Car/Car-admin/src/main/resources/static/images/";
        //获得服务路径
        UUID id= UUID.randomUUID();
        System.out.println("路径" + filePath);
        try{
            FileUtil.uploadFile(file.getBytes(),filePath,fileName);
            msg.setMsg("上传成功");
            msg.setCode(1);
            msg.setData(fileName);
        }catch (Exception e){
            msg.setMsg("上传失败了!!");
        }
        return msg;
    }
}
